<?php

/***************************************************************\
* FILE:		sys/pages/unsubscribe.inc
* SECTION:	pages > user management
* FUNCTION:	
* USES:	
* INCLUDES:		
* PRODUCES:	
* LAUNCHES:	
\***************************************************************/

/**
 * adds extra access checks, dependent on page state
 */
function page_inc_check_access() {
	check_access("VIEW");
}


function page_inc_execute_action($action) {
	switch($action) {
		default:
			add_alert("unknown action: $action");
			break;
	}
}


/**
 * execute page logic
 */
function page_inc_execute() {
	global $PAGE, $CONFIG;

	if (!$_GET['code'] or !$PAGE['id'])
		errorpage(9);

	$sqlresult = db_do_query(db_query_select(array(array('*')), array("MEMBER"), ereg("^[0-9]+$", $PAGE['id']) ? "user_id = {$PAGE['id']}" : "nick = '{$PAGE['id']}'"));
	
	if (db_num_rows($sqlresult) != 1)
		errorpage(9);
		
	$user = db_fetch_array($sqlresult);
	
	if ($_GET['code'] == (md5("{$user['nick']}{$user['email']}UNSUBSCRIBE"))) {
	
		db_do_query(db_query_update(array('member_since', 'last_visit', 'last_click', 'pref_newsletter'), array('member_since', 'last_visit', 'last_click', 0), "MEMBER", "user_id = {$user['user_id']}"));
		
		endpage("OK, '{$user['email']}' ontvang niet langer de mandragon nieuwsbrief. <script language=JavaScript>setTimeout(\"location.href='{$CONFIG['homedir']}'\", 5000);</script>");
	
	} else
		errorpage(14);
}

/**
 * dress up page content using skin stuff
 */
function page_inc_dress() {}

?>